﻿Imports System.Data.OleDb
Public Class NhatKiDAO
    Public Shared Function LoadND(ByVal nhk As NhatKiDTO) As DataTable
        Dim Sql As String = "Select NoiDung From NhatKi  Where Ngay=#" + nhk.Ngay.ToShortDateString() + "#"
        Dim Cn As OleDbConnection
        Cn = DataProvider.OpenCn()
        Dim da As New OleDbDataAdapter(Sql, Cn)
        Dim dt As New DataTable
        da.Fill(dt)
        Cn.Close()
        Return dt
    End Function

    Public Shared Function LoadThoiGian() As DataTable
        Dim sql As String = "Select Sum(HuuIch), Sum(KhongHuuIch), Sum(KhongTen) From NhatKi"
        Dim Cn As OleDbConnection
        Cn = DataProvider.OpenCn()
        Dim da As New OleDbDataAdapter(sql, Cn)
        Dim dt As New DataTable
        da.Fill(dt)
        Cn.Close()
        Return dt
    End Function

    Public Shared Function Check(ByVal nhk As NhatKiDTO) As Boolean
        Dim Sql As String = "Select * from NhatKi Where Ngay=#" + nhk.Ngay.ToShortDateString() + "#"
        Dim cn As OleDbConnection
        cn = DataProvider.OpenCn()
        Dim da As New OleDbDataAdapter(Sql, cn)
        Dim dt As New DataTable
        da.Fill(dt)
        cn.Close()
        If (dt.Rows.Count > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Shared Sub ThemNK(ByVal nhk As NhatKiDTO)
        Dim sql As String = "Insert Into NhatKi(Ngay,NoiDung) Values(#" + nhk.Ngay.ToShortDateString() + "#,'" + nhk.NoiDung + "')"
        Dim cn As OleDbConnection
        cn = DataProvider.OpenCn()
        Dim cm As New OleDbCommand(sql, cn)
        cm.ExecuteNonQuery()
        cn.Close()
    End Sub

    Shared Sub UpdateTG(ByVal nhk As NhatKiDTO)
        Dim sql As String = "Update NhatKi Set HuuIch=HuuIch+" + nhk.HuIch + " KhongHuuIch=KhongHuuIch+" + nhk.KhongHuuIch + " KhongTen=KhongTen+" + nhk.KhongTen + " Where Ngay=#" + nhk.Ngay.ToShortDateString() + "#"
        Dim cn As OleDbConnection
        cn = DataProvider.OpenCn()
        Dim cm As New OleDbCommand(sql, cn)
        cm.ExecuteNonQuery()
        cn.Close()
    End Sub

    Shared Sub UpdateNK(ByVal nhk As NhatKiDTO)
        Dim Sql As String = "Update NhatKi Set NoiDung='" + nhk.NoiDung + "' where Ngay=#" + nhk.Ngay.ToShortDateString() + "#"
        Dim cn As OleDbConnection
        cn = DataProvider.OpenCn()
        Dim cm As New OleDbCommand(Sql, cn)
        cm.ExecuteNonQuery()
        cn.Close()
    End Sub
End Class
